/** @file myAllegro.cpp
  *
  * Funkcje skladowe klasy MyAllegro
  */

#include "myAllegro.h"

MyAllegro::MyAllegro(unsigned int w, unsigned int h) : W(w), H(h) {
  srand(time(NULL));
  allegro_init();
  install_timer();
  install_keyboard();
  install_mouse();

  set_color_depth(32);
  if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, W, H, 0, 0) != 0) {
    allegro_exit();
    exit(1);
  }

  set_palette(desktop_palette);
  buffer = create_bitmap(W, H);
}

MyAllegro::~MyAllegro() {
  destroy_bitmap(buffer);
  allegro_exit();
}

void MyAllegro::doubleBuffering() {
  acquire_screen();
  blit(buffer, screen, 0, 0, 0, 0, W, H);
  release_screen();
}

void MyAllegro::drawCursor() {
  putpixel(buffer, mouse_x, mouse_y, makecol(255,255,255));
  circle(buffer, mouse_x, mouse_y, 2, makecol(255,100,100));
}

/// @todo W dalszym ciagu kolor moze byc slabo widoczny.
const int MyAllegro::cRandom() {
  int col;
  while((col = makecol((rand()%156)+100, (rand()%156)+100, (rand()%156)+100)) == makecol(SBG_COLOR.R, SBG_COLOR.G, SBG_COLOR.B))
  {}
  return col;
}
